<template>
  <el-form ref="form" label-width="100px">
  <el-form-item label="总融资金额" style="width:500px">
    <el-input v-model="allFinancingAmount"></el-input>
  </el-form-item>
  <el-form-item label="融资期限" style="width:500px">
    <el-input v-model="financingLimit"></el-input>
  </el-form-item>
  <el-form-item label="核心企业选择">
    <el-select v-model="coreId" placeholder="请选择核心企业">
      <el-option v-for="c in core" :key="c.coreId" :label="c.enterpriseName" :value="c.coreId"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="年华利率" style="width:500px">
    <el-input v-model="annualizedInterestRate"></el-input>
  </el-form-item>
  <el-form-item label="资产选择" style="width:500px">
    <el-select v-model="assetId" placeholder="请选择抵押资产">
      <el-option v-for="t in tableData" :key="t.id" :label="t.assetName" :value="t.id"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="背书凭证" style="width:500px">
    <el-upload
            class="upload-demo"
            action="/api/uploadimg"
            list-type="picture"
            :file-list="fileList1"
            :headers="headers"
            :on-success="handleAvatarSuccess">
        <el-button size="small" type="primary">点击上传</el-button>
        <div slot="tip" class="el-upload__tip" style="color:brown">只能上传jpg/png文件，且不超过200MB</div>
    </el-upload>
  </el-form-item>


  <el-form-item>
    <el-button type="primary" @click="doAdd()" style="margin-left:110px">立即创建</el-button>
  </el-form-item>
</el-form>
</template>

<script>
export default {
    data(){
        return{
          tableData:[],
          total: 0,
            pageNum: 1,
            pageSize: 5,
          headers:{
          'jwt':localStorage.getItem('jwt')
        },
          fileList1:[],
            coreId:'',
            allFinancingAmount:'',
            financingLimit:'',
            annualizedInterestRate:'',
            assetId:'',
            tenderImages:'',
            core:[]
        }
    },
    methods:{
      handleAvatarSuccess(res, file){
          console.log(res)
          this.tenderImages = res.msg
        },
      handleRemove(file, fileList1) {
        console.log(file, fileList1);
      },
      handlePreview(file) {
        console.log(file);
      },
        selectCore(){
          let jwt = localStorage.getItem("jwt");
          this.$axios.get('api/CoreEnterprise/findCoreByName',{headers:{'jwt':jwt}})
          .then(res =>{
              if(res.data.code == 200){
                console.log(res.data)
                this.core = res.data.data

              }
          })
        },
        selectAsset(){
          let jwt = localStorage.getItem("jwt");
            let param = {};
            param.pageNum = this.pageNum;
            param.pageSize = this.pageSize;
            let enterpriseId=localStorage.getItem("enterpriseId");
            let data = {};
            
            data.ownedEnterprise=enterpriseId;
            param.data = data;

            this.$axios.post('api/finance/asset/findAllAssetByFinanceId', param, { headers: { "jwt": jwt } }).then(res => {
                if (res.data.code == 200) {
                    this.tableData = res.data.data.list;
                    console.log(this.tableData)

                }

            })
        },
        doAdd(){
            let jwt = localStorage.getItem('jwt')
            let enterpriseId = localStorage.getItem('enterpriseId')
            this.$axios({
                url:'api/finance/tender/saveTender',
                method:'post',
                data:{
                    financeId:enterpriseId,
                    coreId:this.coreId,
                    allFinancingAmount:this.allFinancingAmount,
                    financingLimit:this.financingLimit,
                    annualizedInterestRate:this.annualizedInterestRate,
                    tenderImages:this.tenderImages,
                    assetId:this.assetId
                 
                },
                headers:{jwt:jwt}
            }).then(res=>{
              console.log(res.data)
                if(res.data.code==200){
                  this.fileList1=[]
                    this.$router.push('queryTender')
                }else{
                    alert("......")
                }
            })
        },
    },
    created(){
        this.selectCore()
        this.selectAsset()
    }
}
</script>

<style scoped>
    .ok{
        text-align: center;
    }
</style>